﻿
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[sproc_UpdateProject]') AND type in (N'P', N'PC'))
    DROP PROCEDURE [dbo].[sproc_UpdateProject];
GO
CREATE PROCEDURE [dbo].[sproc_UpdateProject] 
    @ProjectID int,
    @ProjectName nvarchar(50),
    @ProjectRemark text,
    @Status int,
    @Scale int,
    @StartDate datetime,
    @EndDate datetime
/*

============================================================
功能:    更新项目的信息
参数:
    @ProjectID int            :    项目ID
    @ProjectName nvarchar(50)    :    项目名字
    @ProjectRemark text        :    项目介绍
    @Status int            :    项目状态
    @Scale int            :    项目所占比例
    @StartDate datetime        :    项目开始时间
    @EndDate datetime        :    项目结束时间

============================================================

*/
AS
--更新项目基本信息
UPDATE uds_class 
    SET 
    classname=@ProjectName,
    classremark=@ProjectRemark,
    status=@Status
    WHERE classid = @ProjectID
--判断项目相关信息，有则更新，无则添加
IF EXISTS(SELECT 1 FROM uds_teaminfo WHERE teamid = @ProjectID)
BEGIN
    UPDATE uds_teaminfo 
        SET
        scale=@Scale,
        startdate=@StartDate,
        enddate=@EndDate
        WHERE teamid = @ProjectID
END
ELSE
BEGIN
    INSERT INTO uds_teaminfo (teamid,scale,startdate,enddate)
        VALUES(@ProjectID,@Scale,@StartDate,@EndDate)
END